home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / filters.zip / SNGLSPC.ASM < prev    next >
Assembly Source File  |  1986-11-27  |  3KB  |  120 lines

  1.     Name Snglspc
  2.     Title    Convert doublespace to singlespace (remove blank lines.)
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that delete blank lines from a file.
  7.  
  8.     Examples:
  9.         Snglspc abc.txt        read input from abc.txt,
  10.         Snglspc abc.txt >abcnew.txt
  11.         Snglspc <abc.txt >abcnew.txt
  12.         Snglspc abc.txt | find "ABC"
  13.         find "abc" abc.txt | Snglspc | sort
  14. /
  15. ;===================================================================
  16. code    segment    public
  17. ;===================================================================
  18. ;
  19. ;    command line is at 80h of psp - first byte is length
  20. ;
  21.     org    80h
  22. parmsize    db    ?
  23. parm        db    7fh dup (?)
  24. ;
  25. ; .com starts at 100h - but must jump around any data area
  26. ;
  27.     org    100h            ; com file starts here
  28.     assume    cs:code,ds:code,es:code
  29. snglspc:
  30.     jmp    clear
  31. ;===================================================================
  32. ;
  33. ; data area for .com programs
  34. ;
  35. cr    equ    0dh
  36. lf    equ    0ah
  37. eof    equ    1ah
  38. ;
  39. handle    dw    0h            ; assume standard input
  40. bufsiz    equ    255
  41. bufferin    db    bufsiz dup (?)
  42. bufferout    db    bufsiz dup (?)
  43. flag        db    0h
  44. outcount    dw    0h        ; output char count
  45. ;
  46. ;===================================================================
  47. clear:
  48. ;
  49. ; start of actual code is here (clear)
  50. ;
  51. ;
  52. ; now figure out which file to read from - parm line or standard input
  53. ;
  54.     cmp    parmsize,0h    ; if zero, no parm
  55.     jz    again        ; assume standard input
  56. ;
  57. ; parm length is not zero - assume the parm is a file name.  If not
  58. ; found, quit.
  59. ;
  60.     mov    al,parmsize    ; get size of parm
  61.     xor    ah,ah        ; zero out top part of accum.
  62.     mov    si,ax        ; use length as a pointer into the dta
  63.     mov    [si]+parm,0h    ; to tack on a zero byte (asciiz).
  64. ;
  65. ; now try to open the file
  66. ;
  67.     lea    dx,parm+1    ; address of 'filename'
  68.     mov    al,0h        ; open for read only
  69.     mov    ah,3dh        ; dos open function
  70.     int    21h        ; invoke function
  71.     jc    oops        ; open error - quit
  72.     mov    handle,ax    ; save file handle
  73. again:
  74.     mov    bx,handle    ; read from standard input or file
  75.     mov    cx,bufsiz    ; # of characters to read
  76.     lea    dx,bufferin    ; seg:off address of buffer area
  77.     mov    ah,3fh        ; dos read function
  78.     int    21h        ; invoke function
  79. ;
  80.     jc    oops        ; error!
  81.     cmp    ax,0h        ; if zero, end of file
  82.     jz    oops
  83. ;
  84.     mov    cx,ax        ; cx (and ax) contain # characters read
  85.     mov    outcount,0h    ; init output character counter
  86.     lea    si,bufferin    ; offset of buffer
  87.     lea    di,bufferout    ; address of output area
  88. loop1:
  89.     lodsb               ; get a character.  If cr or lf,
  90.     cmp    al,cr        ; increment flag.
  91.     jne    next
  92.     add    flag,1h
  93.     jmp    next3
  94. next:
  95.     cmp    al,lf
  96.     jne    next2
  97.     add    flag,1h
  98.     jmp    next3
  99. next2:
  100.     mov    flag,0h        ; not cr/lf, reset flag
  101. next3:
  102.     cmp    flag,02h    ; if flag is greater than 2, skip
  103.     jg    skip        ; the characters.
  104.     inc    outcount    ; increment count of characters output
  105.     stosb
  106. skip:
  107.     loop    loop1        ; and repeat for entire buffer
  108. ;
  109.     mov    cx,outcount    ; restore character count
  110.     mov    bx,1h        ; standard output device
  111.     lea    dx,bufferout    ; output buffer
  112.     mov    ah,40h        ; dos write function
  113.     int    21h        ; invoke dos function
  114.  
  115.     jmp    again        ; repeat until end of file or error
  116. oops:
  117.     int    20h        ; return to dos
  118. code    ends
  119.     end    snglspc
  120.